using System;
using Services;
using Utilities;
using System.Linq;
using JigLibX.Physics;
using JigLibX.Geometry;
using System.Threading;
using JigLibX.Collision;
using Microsoft.Xna.Framework;
using System.Collections.Generic;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.GamerServices;

namespace SpaceBattle.Logic.SampleLevel
{
    using Game = Microsoft.Xna.Framework.Game;
    
    public abstract class ShockWavesLayer : ProjectilesLayer
    {
        public ShockWavesLayer(Game game, BaseLevelStats current_score, ShipType player_ship, int num_lives)
            : base(game, current_score, player_ship, num_lives)
        {
        }

        protected override void UpdateShockWaves(float dt)
        {
            var slow_motion = CurrentState.slow_motion;
            var current_score = CurrentScore;

            /// Aggiorno le shockwaves
            for (int i = 0; i < CurrentState.shockwaves.Count; i++)
            {
                var sw = CurrentState.shockwaves[i];

                sw.radius += sw.speed * dt;
                if (sw.radius > sw.range)
                {
                    CurrentState.RemoveShockWaveAt(i);
                    i--;
                }
            }
        }

        protected override void ShootShockWave(Vector3 newposition, Faction newfaction, Color newinitialColor, Color newfinalColor, float newrange, float newspeed, float newdamage, Ship shooter)
        {
            var sw = new ShockWave(true)// costruttore NON di default: alloca questa reference nel pool
                    {
                        position = newposition,
                        faction = newfaction,
                        initialColor = newinitialColor,
                        finalColor = newfinalColor,
                        range = newrange,
                        speed = newspeed,
                        damage = newdamage,
                        radius = 0.0f,
                        shooter = shooter
                    };
            CurrentState.shockwaves.Add(sw);
            NewShockWaves.Add(sw);
            audio_service.OnShockwaveShoot();
        }

    }
}